from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from pathlib import Path
import orjson

path = Path(__file__).absolute().parent

SQLALCHEMY_BINDS = {
    "db1": f"mysql+pymysql://root:root@localhost:3306/flower"
}

ECHO = False

engine1 = create_engine(
    SQLALCHEMY_BINDS["db1"],
    json_serializer=lambda obj: orjson.dumps(obj),
    json_deserializer=lambda obj: orjson.loads(obj),
    echo=ECHO
)

SessionLocal = sessionmaker(autocommit=False, autoflush=False)

# 数据库映射基类
DB1 = declarative_base()

SessionLocal.configure(binds={DB1: engine1})
